import { StoreOptions } from "vuex";
import{UserControllerService} from "../../generated";
import ACCESS_ENUM from "@/access/accessEnum";

export default {
  //表示该模块是有命名空间的
  namespaced: true,
//全局状态管理
  state:()=>({
    loginUser:{
      userName:"未登录",
    }
  }),
  getters: {

  },
  //变更信息
  mutations: {
    updateUser(state,payload){
      state.loginUser = payload;
    },

  },
  //异步操作 调用 mutations
  actions: {
    async getLoginUser({ commit, state }, payload) {
      // 从远程请求获取登录信息
      const res = await UserControllerService.getLoginUserUsingGet();
      if (res.code === 0) {
        commit("updateUser", res.data);
      } else {
        commit("updateUser", {
          ...state.loginUser,
          userRole: ACCESS_ENUM.NOT_LOGIN,
        });
      }
    },
  },

  //把一个大的 state 分成多个小的状态  比如用户状态只有用户的 状态
  modules: {

  },
} as StoreOptions<any>;
